package net.jiastudy.web.rest.controller.targettask;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.jiastudy.biz.targettask.entity.TargetWork;
import net.jiastudy.biz.targettask.service.TargetWorkService;
import net.jiastudy.core.base.BaseController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/targettask/{taskId}/targetwork")
@Api(value = "TargetWorkController  目标工作")
public class TargetWorkController extends BaseController {
    @Resource
    private TargetWorkService targetWorkService;

    @RequestMapping(method = RequestMethod.POST)
    @ApiOperation(value = "布置工作", notes = "")
    public TargetWork create(@PathVariable Long taskId, @RequestBody TargetWork targetWork) {
        targetWork.setTargetTaskId(taskId);
        return targetWorkService.createWork(targetWork);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation(value = "工作列表", notes = "")
    public List<TargetWork> findByTaskId(@PathVariable Long taskId) {
        return targetWorkService.findByTaskId(taskId);
    }

    @RequestMapping(path = "/{workId}", method = RequestMethod.DELETE)
    @ApiOperation(value = "工作删除", notes = "")
    public Boolean delete(@PathVariable Long workId) {
        return targetWorkService.deleteWorkById(workId);
    }

    @RequestMapping(path = "/{workId}", method = RequestMethod.PUT)
    @ApiOperation(value = "工作编辑", notes = "")
    public TargetWork edit(@PathVariable Long workId, @RequestBody TargetWork targetWork) {
        targetWork.setId(workId);

        return targetWorkService.updateTargetWork(targetWork);
    }
}
